package com.unittec.zk.provider.work.controller;

import com.alibaba.fastjson.JSON;
import com.unittec.zk.provider.log.Log;
import com.unittec.zk.provider.utils.ValidationUtils;
import com.unittec.zk.provider.work.service.WorkPlanRecordsService;
import com.unittec.zk.provider.work.service.WorkPlanService;
import com.unittec.zk.sdk.log.enums.LogOperateEnum;
import com.unittec.zk.sdk.log.enums.LogStatusEnum;
import com.unittec.zk.sdk.root.domain.GatewayRequest;
import com.unittec.zk.sdk.root.domain.Result;
import com.unittec.zk.sdk.root.enums.BizCode;
import com.unittec.zk.sdk.root.enums.BizCodeEnum;
import com.unittec.zk.sdk.work.request.Req202010;
import com.unittec.zk.sdk.work.request.Req202022;
import com.unittec.zk.sdk.work.response.Res202000;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags="工作总结管理")
public class WorkPlanRecordsController {

    @Resource
    private Log log;

    @Resource
    private WorkPlanRecordsService service;
    //工作总结-详情

    @RequestMapping(value = "/202022", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "工作总结详情", notes = "工作总结详情")
    public  Result<Res202000> wordPlanRecordsDetail(@RequestBody GatewayRequest<Req202022> req){
        log.debug(req, "wordPlanRecordsDetail {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res202000 res202000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = service.workPlanRecordsDetail(req.getContent());
            res202000 = new Res202000();
            res202000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("202022", JSON.toJSONString(req), "工作总结详情", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "wordPlanRecordsDetail {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("202022", JSON.toJSONString(req), "工作总结详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res202000);
        } else {
            log.addOperateLog("202022", JSON.toJSONString(req), "工作总结详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

}
